unit PacocStringManipulation;

interface

function  Replace(Text, FindStr, ReplaceStr: String): String;
function  GetNumbers(Text: String)                  : String;
function  GetLetters(Text: String)                  : String;
function  GetOthers(Text: String)                   : String;
function  TrimNumbers(Text: String)                 : String;
function  TrimLetters(Text: String)                 : String;
function  TrimOthers(Text: String)                  : String;
function  Capitalize(S: String)                     : String;
function  PosEx(Search, S: String; From: Integer)   : Integer;
procedure Delete(var s: string; ifrom, icount: LongInt);

implementation

uses SysUtils, ClickIt, Math, StrUtils;

function Replace(Text, FindStr, ReplaceStr: string): string;
begin
  result := StringReplace(Text, FindStr, ReplaceStr, [rfReplaceAll]);
end;

function GetNumbers(Text: string): string;
var
  I: Integer;
begin
  for I:= 1 to Length(Text) do
    if(Text[I] in ['0'..'9'])then
      Result:= Result + Text[I];
end;

function GetLetters(Text: String): String;
var
  I: Integer;
begin
  for I:= 1 to Length(Text) do
    if(Text[I] in ['a'..'z'] + ['A'..'Z'])then
      Result:= Result + Text[I];
end;

function GetOthers(Text: String): String;
var
  I: Integer;
begin
  for I:= 1 to Length(Text) do
    if(not(Text[I] in ['a'..'z'] + ['A'..'Z'] + ['0'..'9']))then
      Result:= Result + Text[I];
end;

function TrimNumbers(Text: String): String;
var
  I: Integer;
begin
  for I:= 1 to Length(Text) do
    if(not(Text[I] in ['0'..'9']))then
      Result:= Result + Text[I];
end;

function TrimLetters(Text: String): String;
var
  I: Integer;
begin
  for I:= 1 to Length(Text) do
    if(not(Text[I] in ['a'..'z'] + ['A'..'Z']))then
      Result:= Result + Text[I];
end;

function TrimOthers(Text: String): String;
var
  I: Integer;
begin
  for I:= 1 to Length(Text) do
    if(Text[I] in ['a'..'z'] + ['A'..'Z'] + ['0'..'9'])then
      Result:= Result + Text[I];
end;

function Capitalize(S: String): String;
var
  I: Integer;
  CapNext: Boolean;
begin
  CapNext:= True;
  for I:= 1 to Length(S) do
    if(CapNext)then
    begin
      if(S[I] in ['a'..'z'] + ['A'..'Z'] + ['0'..'9'])then
      begin
        S[I]:= UpCase(S[I]);
        CapNext:= False;
      end;
    end else if(S[I] = ' ')then CapNext:= True;
  Result:= S;
end;

function PosEx(Search, S: String; From: Integer): Integer;
begin
  Result:= StrUtils.PosEx(Search, S, From);
end;

procedure Delete(var s: string; ifrom, icount: LongInt);
begin
  s:= copy(s, 1, ifrom - 1) + copy(s, ifrom + icount, Length(s));
end;

end.
